package com.test.mooan.labama.dialog_boom;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.test.mooan.labama.R;
import com.test.mooan.labama.utils_boom.Stringutil_boom;
import com.test.mooan.labama.utils_boom.Threadutils_boom;


public class MsgDialog_boom extends Dialog {

    private final String text;
    private final Runnable onClickListener;
    private final long time;

    public MsgDialog_boom(@NonNull Context context, String text, long time, Runnable onClickListener) {
        super(context);
        this.text = text;
        this.onClickListener = onClickListener;
        this.time = time;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_msg_boom);
        getWindow().setBackgroundDrawableResource(R.color.trans);
        setCanceledOnTouchOutside(false);
        initView();
    }

    @SuppressLint({"SetTextI18n", "ResourceAsColor"})
    private void initView(){

        TextView textTv = findViewById(R.id.dialog_msg_tv_text);

        textTv.setText(Stringutil_boom.getSafeString(text));

        Threadutils_boom.getInstance().postDelay(() -> {
            dismiss();
            if (onClickListener!=null) onClickListener.run();
        },time);
    }

}
